package com.am.servlet;

import com.am.bean.Role;
import com.am.service.RoleService;
import com.utils.Meg;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class RoleServlet {

    @Autowired
    private RoleService roleService;

    @RequestMapping("/roleView")
    public String roleView(){
        return "role/role";
    }

    @RequestMapping("/roleEditView")
    public String roleEditView(){
        return "role/rolePage";
    }

    @RequestMapping("/roleAddView")
    public String roleAddView(){
        return "role/roleAdd";
    }

    @ResponseBody
    @RequestMapping("/roleData")
    public Meg roleData(@Param("page") String page, @Param("limit") String limit){
        return Meg.success().add("data",roleService.selectAll(limit,page));
    }

    @ResponseBody
    @RequestMapping("/roleInsert")
    public Meg roleInsert(Role role){
        int i = roleService.insert(role);
        if (i>0)
            return Meg.success();
        else
            return  Meg.file();
    }

    @ResponseBody
    @RequestMapping("/roleUpdate")
    public Meg roleUpdate(Role role){
        int i = roleService.update(role);
        if (i>0)
            return Meg.success();
        else
            return  Meg.file();
    }

    @ResponseBody
    @RequestMapping("/roleDelete")
    public Meg roleDelete(@Param("id") Integer id){
        int i = roleService.delete(id);
        if (i>0)
            return Meg.success();
        else
            return  Meg.file();
    }
    @ResponseBody
    @RequestMapping("/roleActivate")
    public Meg menuAction(@Param("id")Integer id,@Param("roleActivate")String roleActivate){
        roleService.Action(id,roleActivate);

        return Meg.success();
    }
}
